package cn.itsource.pethome.product.controller;

import cn.itsource.pethome.Basic.util.AjaxResult;
import cn.itsource.pethome.product.domain.Product;
import cn.itsource.pethome.product.domain.ProductDetail;
import cn.itsource.pethome.product.service.IProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productDetail")
public class ProductDetailController {
    @Autowired
    private IProductDetailService productDetailService;

    /**
     * 根据条件查询服务
     *
     * @return
     */
    @PatchMapping
    public List<ProductDetail> loadProductDetailsByQuery() {
        return productDetailService.loadAll();
    }


    /**
     * 删除服务
     *
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public AjaxResult deleteProductDetail(@PathVariable("id") Long id) {
        try {
            productDetailService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "删除失败" + e.getMessage());
        }
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PatchMapping("/batchRemove")
    public AjaxResult batchRemove(@RequestBody Long[] ids) {
        try {
            productDetailService.batchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "删除失败" + e.getMessage());
        }
    }

}